//
//  CourseViewController.m
//  Codingke2016
//
//  Created by xujiangtao on 16/5/30.
//  Copyright © 2016年 xujiangtao. All rights reserved.
//

#import "CourseViewController.h"
#import "SelecterToolsScrolView.h"
#import "SelecterContentScrollView.h"
#import "CourseContentViewController.h"


@interface CourseViewController ()

@property(nonatomic,retain)NSArray *titleArr;// 标题数组
@property(nonatomic,retain)NSMutableArray *vcArr;// viewcontroller 数组

@property(nonatomic,retain)SelecterToolsScrolView *selectTools;
@property(nonatomic,retain)SelecterContentScrollView *contentScrView;


@end

@implementation CourseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor whiteColor];
    
    self.automaticallyAdjustsScrollViewInsets =NO;
    
    _titleArr = @[@"全部",@"H5",@"UI",@"iOS",@"Android"];
    
    _vcArr = [NSMutableArray array];
    
    for (int i = 0; i < _titleArr.count ; i++) {
        CourseContentViewController *contentVc = [[CourseContentViewController alloc]init];
        [self addChildViewController:contentVc];
        [_vcArr addObject:contentVc];
    }
    [self createSelecterToolsScrollView];
    [self createContentVCScrollView];
    
    UIView *lineView =[[UIView alloc] initWithFrame:CGRectMake(0,NAV_HEIGHT+39,SCREEN_WIDTH,1)];
    lineView.backgroundColor =[UIColor colorWithHexString:@"#c0bfbf"];
    [self.view addSubview:lineView];
}
-(void)createSelecterToolsScrollView
{
    __weak typeof(self) weakSelf = self;
    
    _selectTools = [[SelecterToolsScrolView alloc]initWithSeleterConditionTitleArr:_titleArr andBtnBlock:^(UIButton * btn) {
        [weakSelf updateVCViewFrom:btn.tag];
    }];
    [self.view addSubview:_selectTools];
}

-(void)createContentVCScrollView
{
    __weak typeof(self) weakSelf = self;
    _contentScrView = [[SelecterContentScrollView alloc]initWithSeleterConditionTitleArr:_vcArr andBtnBlock:^(int index) {
        [weakSelf updateSelectToolsIndex:index];
    }];
    [self.view addSubview:_contentScrView];
}


-(void)updateSelectToolsIndex:(NSInteger)index
{
    [_selectTools updateSelecterToolsIndex:index];
}

-(void)updateVCViewFrom:(NSInteger )index
{
    [_contentScrView updateVCViewFromIndex:index];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
